/**
 * 地刺道具  地刺在拖场景的时候静态地刺命名spikes 动态地刺以“spikes_”up/down/left/right  命名
 */
cc.Class({
    extends: cc.Component,

    properties: {

    },

    onLoad() {
        let type = this.node.name.split('_')[1];
        this.limit = 30;//地刺的最大长度
        this.pos = 0;
        switch (type) {
            case 'up':
                this.distence = 2;
                this.dir = 'y';
                break;
            case 'down':
                this.distence = -2;
                this.dir = 'y';
                break;
            case 'left':
                this.distence = -2;
                this.dir = 'x';
                break;
            case 'right':
                this.distence = 2;
                this.dir = 'x';
                break;
            default:
                break;
        }
    },
    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function (contact, selfCollider, otherCollider) {
        

    },


    update(dt) {//地刺的移动和地刺移动到最大值时反向移动
        this.pos += this.distence;
        this.node[this.dir] += this.distence;
        if (Math.abs(this.pos) === this.limit) {
            this.distence *= -1;
        }
    },
});
